<template>
<div>
    <div>
        <h2>登录</h2>
    </div>
    <van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="username"
      name="用户名"
      label="用户名"
      placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
      v-model="password"
      type="password"
      name="密码"
      label="密码"
      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    />
  </van-cell-group>
</van-form>
<van-button ccolor="yellow" @click="login">登录</van-button>
</div>
  
</template>

<script>
export default {
    data(){
        return{
            username:'',
            password:'',
        }
    },
    methods:{
        login(){
        this.myaxios(this.baseURL + 'login/','get',{username:this.username,password:this.password}).then(resp=>{
        console.log('登录',resp)
        if(resp.errcode==0){
          this.$toast.success(resp.msg)
          localStorage.setItem('ks_uid',resp.uid)
          localStorage.setItem('ks_username',resp.username)
          window.location.href = '/ks_index'
        }else{
          this.$toast.fail('发帖失败')
        }
      })
        }
    }

}
</script>

<style>

</style>